<?
require_once('config.php');
$action = getValue('action','str','POST');
if($action == 'submit'){
   $vid_name         = getValue('vid_name','str','POST','Chưa nhập');
   $vid_image  = getValue('vid_image','str','POST','');
   $cat_id     = getValue('cat_id','int','POST');
   $per_id     = getValue('per_id','str','POST');
   $vid_lyric  = getValue('vid_lyric','str','POST','Chưa nhập');
   $sql = "INSERT INTO video( vid_name,
                              vid_image,
                              cat_id,
                              vid_lyric,
                              vid_date
                              )
                        VALUES(
                              '" .$vid_name. "',
                              '" .$vid_image. "',
                              " .$cat_id. ",
                              '" .$vid_lyric. "',
                              ".time()."
                              )";
               
   $db_execute_return = new db_execute_return;
   $vid_id  = $db_execute_return->db_execute($sql);
   // per_id là dạng chuỗi. Mỗi per_id được phân cách nhau bởi 1 dấu phảy ","
   if($per_id != '') {
      $sql        = "INSERT INTO vid_per(vid_id,per_id) 
                         VALUES";
      $sql_value  = '';
      $array_per_id = explode(',',$per_id);
      foreach($array_per_id as $value){
         $sql_value .= "(" . $vid_id . "," . $value . "),";
      }
      $sql_value = substr($sql_value,0,-1);
      $sql .= $sql_value;
      $db_exe  = new db_execute($sql);
      unset($db_exe);    
   }
   echo '<span style="color: #01B42C;font-size: 14px;font-weight: bold;">Thêm thành công</span>';
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Thêm mới <?=$moduol_name?></title>
   <?=$css_global?>
   <?=$js_global?>
  <script>
  $(function() {
    $( "#datepicker" ).datepicker();
    $(document).on('click','.reload_tab' ,function(){
      window.location.reload();
    });
  });
  </script>
</head>
<div class="row-fluid">
   <div class="head">
      <div class="isw-grid"></div>
      <h1>Thêm mới <?=$moduol_name?></h1>      
      <div class="reload_tab" title="Reload"></div>                         
      <div class="clear"></div>
   </div>
   <div class="block-fluid">
      <form class="form-horizontal" name="add" action="" method="POST" enctype="multipart/form-data"  onsubmit="">
         <input type="hidden" name="action" value="submit" />
         <fieldset>
            <div class="control-group">
               <label class="control-label" for="input01">Tên video</label>
               <div class="controls">
						<input type="text" class="input-xlarge tooltip-right span8" id="vid_name" name="vid_name" title="Tên video"/>
					</div>
            </div>
            <div class="control-group">
               <label class="control-label" for="input01">Link Ảnh</label>
               <div class="controls">
						<input type="text" class="input-xlarge tooltip-right span8" id="vid_image" name="vid_image" title="Link ảnh"/>
					</div>
            </div>
            <div class="control-group">
               <label class="control-label" for="input01">Chọn thể loại</label>
               <div class="controls">
						<select id="cat_id" name="cat_id">
                     <option value="0">Không chọn</option>
                     <?if($count_cat > 0):?>
                        <?foreach($array_all_cat as $key=>$value):?>
                           <option value="<?=$key?>"><?=$value?></option>
                        <?endforeach?>
                     <?endif?>
                  </select>
					</div>
            </div>
            <div class="control-group">
               <label class="control-label" for="input01">Chọn ca sĩ</label>
               <div class="controls">
                 <input type="text" id="per_id" name="per_id" />
                 
                 <script type="text/javascript">
                 $(document).ready(function() {
                     $("#per_id").tokenInput("ajax_token_input_person.php", {
                        theme: "facebook",
                        preventDuplicates: true,
                     });
                     
                 });
                 </script>
					</div>
            </div>
            <div class="control-group">
               <label class="control-label" for="input01">Lời bài hát</label>
               <div class="controls">
						<textarea  name="vid_lyric" id="vid_lyric"></textarea>
                  <script type="text/javascript">CKEDITOR.replace('vid_lyric'); </script>
					</div>
            </div>
            <div class="form-actions">
					<button type="submit" class="btn btn-info">Thêm mới</button>
					<button type="reset"  class="btn btn-warning">Làm lại</button>
				</div>
         </fieldset>
      </form>
   </div> 
</div>